package com.haiqi.modules.ship.service;

import com.alibaba.druid.util.StringUtils;
import com.github.pagehelper.PageInfo;
import com.haiqi.common.bean.PageBean;
import com.haiqi.common.persistence.dao.CrewUserMapper;
import com.haiqi.common.persistence.dao.ShipInfoMapper;
import com.haiqi.common.persistence.entity.ShipInfo;
import com.haiqi.common.utils.PageUtils;
import com.haiqi.common.utils.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by hythzx on 2016/5/25.
 */
@Service
//@EnableCaching
public class ShipService {

    @Autowired
    private ShipInfoMapper shipInfoMapper;
    @Autowired
    private CrewUserMapper crewUserMapper;
    public PageInfo<ShipInfo> getDataList(ShipInfo shipInfo, PageBean page){
        PageUtils.generatePage(page);
        List<ShipInfo> dataList = shipInfoMapper.getDataList(shipInfo);
        PageInfo<ShipInfo> shipInfoList = new PageInfo<ShipInfo>(dataList);
        return shipInfoList;
    }

    public List<ShipInfo> getDataList(ShipInfo shipInfo){
        List<ShipInfo> dataList = shipInfoMapper.getDataList(shipInfo);
        return dataList;
    }

    public ShipInfo getShipInfo(String id){
        ShipInfo shipInfo = shipInfoMapper.selectByPrimaryKey(id);
        return shipInfo;
    }

    public boolean update(ShipInfo shipInfo){
        boolean success = false;
        int count = 0;
        if(StringUtils.isEmpty(shipInfo.getShipid())){
            shipInfo.setShipid(UUIDGenerator.getUUID());
            count = shipInfoMapper.insert(shipInfo);
        }else{
            count = shipInfoMapper.updateByPrimaryKeySelective(shipInfo);
        }
        if(count > 0){
            success = true;
        }
        return success;
    }

    public boolean delete(String id){
        boolean success = false;
        int count = 0;
        count = shipInfoMapper.deleteByPrimaryKey(id);
        if(count > 0){
            success = true;
        }
        return success;
    }

}
